package org.ddd.book.interfaces.controller;

import lombok.AllArgsConstructor;
import org.ddd.book.book.LibraryService;
import org.ddd.book.book.dto.LibraryBaseMessageDTO;
import org.ddd.book.book.dto.LibraryDTO;
import org.ddd.book.book.dto.LibraryInfoDTO;
import org.ddd.book.interfaces.BaseResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/library")
@AllArgsConstructor
public class LibraryController {
    private final LibraryService libraryService;

    /**
     * 注册图书馆（由系统管理员来操作，只注册一次）
     *
     * @param libraryDTO 图书馆
     * @return BaseResult<Boolean>
     */
    @PostMapping("/register")
    public BaseResult<Boolean> registerLibrary(@RequestBody LibraryDTO libraryDTO) {
        libraryService.registerLibrary(libraryDTO);
        return BaseResult.success(true, null);
    }

    @GetMapping
    public BaseResult<List<LibraryInfoDTO>> libraryList() {
        return BaseResult.success(libraryService.listLibrary());
    }

    /**
     * 图书馆详情
     *
     * @param libraryId 图书馆ID
     * @return BaseResult<LibraryInfoDTO>
     */
    @GetMapping("{libraryId}")
    public BaseResult<LibraryInfoDTO> libraryInfo(@PathVariable Long libraryId) {
        return BaseResult.success(libraryService.getLibraryInfo(libraryId));
    }

    /**
     * 移除图书馆
     *
     * @param libraryId 图书馆ID
     * @return public BaseResult<Boolean>
     */
    @PostMapping("/remove/{libraryId}")
    public BaseResult<Boolean> removeLibrary(@PathVariable Long libraryId) {
        libraryService.removeLibrary(libraryId);
        return BaseResult.success(true, null);
    }

    @PostMapping("/baseInfo")
    public BaseResult<Boolean> updateLibraryBaseMessage(@RequestBody LibraryBaseMessageDTO dto) {
        libraryService.updateLibraryBaseMessage(dto);
        return BaseResult.success(true, null);
    }

}
